// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   MenuBar.java

package ui;

import java.io.PrintStream;
import java.util.Vector;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

// Referenced classes of package ui:
//            BrowseCanvas, PageListener, Page

public class MenuBar
{

    public MenuBar(String caption, PageListener listener, Vector submenu, Page src)
    {
        this.listener = listener;
        this.submenu = submenu;
        this.caption = caption;
        this.src = src;
        width = 0;
        height = 0;
        int hf = BrowseCanvas.FONTSMALL.getHeight();
        for(int i = 0; i < submenu.size(); i++)
        {
            height += hf;
            int w = BrowseCanvas.FONTSMALL.stringWidth(submenu.elementAt(i).toString());
            if(w > width)
                width = w;
        }

        width += 8;
        shown = false;
    }

    public void draw(Graphics g, int x, int y, int w, int h)
    {
        g.setColor(BrowseCanvas.menuWarna1);
        y -= height;
        g.fillRect(x - 1, y - 1, width + 10, height + 2);
        g.drawRect(x - 2, y - 2, width + 10, height + 3);
        int hf = BrowseCanvas.FONTSMALL.getHeight();
        g.setFont(BrowseCanvas.FONTSMALL);
        for(int i = 0; i < submenu.size();)
        {
            if(i == selected)
            {
                g.setColor(BrowseCanvas.menuWarna2);
                g.fillRect(x, y + 1, width + 8, hf);
            }
            g.setColor(BrowseCanvas.menuWarna3);
            g.drawString(submenu.elementAt(i).toString(), x + 2, y + 2, 20);
            if(i > 0)
            {
                g.setColor(BrowseCanvas.menuWarna4);
                g.drawLine(x, y + 1, width + 13, y + 1);
                g.setColor(BrowseCanvas.menuWarna5);
                g.drawLine(x, y + 2, width + 13, y + 2);
            }
            i++;
            y += hf;
        }

        g.setColor(BrowseCanvas.menuWarna3);
    }

    public int keyPressed(int keycode)
    {
        if(keycode == BrowseCanvas.KEYDOWN)
        {
            if(selected < submenu.size() - 1)
                selected++;
            else
                selected = 0;
            return 4;
        }
        if(keycode == BrowseCanvas.KEYUP)
        {
            if(selected > 0)
                selected--;
            else
                selected = submenu.size() - 1;
            return 4;
        }
        if(keycode == BrowseCanvas.KEYCENTER || keycode == BrowseCanvas.KEYSOFTLEFT)
        {
            System.out.println("Selected Option : " + selected);
            try
            {
                listener.onMenu(src, selected, (String)submenu.elementAt(selected));
            }
            catch(ClassCastException er)
            {
                listener.onSoftLeftMenu(src, selected);
            }
            shown = false;
            return 3;
        }
        if(keycode == BrowseCanvas.KEYSOFTRIGHT)
        {
            shown = false;
            return 3;
        } else
        {
            return 0;
        }
    }

    public String toString()
    {
        return caption;
    }

    private Vector submenu;
    int width;
    int height;
    private int selected;
    boolean shown;
    public PageListener listener;
    private Page src;
    private String caption;
}
